function out=FQuad(X)

c = 299792.458;

A1 = 15600;
A2 = 18760;
A3 = 17610;
A4 = 19170;

B1 = 7540;
B2 = 2750;
B3 = 14630;
B4 = 610;

C1 = 20140;
C2 = 18610;
C3 = 13480;
C4 = 18390;

t1 = .07074;
t2 = .07220;
t3 = .07690;
t4 = .07242;

ux=2*[A2-A1; A3-A1; A4-A1];
uy=2*[B2-B1; B3-B1; B4-B1];
uz=2*[C2-C1; C3-C1; C4-C1];
ud=2*c^2*[t1-t2; t1-t3; t1-t4];
w=[ A1^2-A2^2+B1^2-B2^2+C1^2-C2^2+c^2*(t2^2-t1^2);
    A1^2-A3^2+B1^2-B3^2+C1^2-C3^2+c^2*(t3^2-t1^2);
    A1^2-A4^2+B1^2-B4^2+C1^2-C4^2+c^2*(t4^2-t1^2)];

mx=det([uy uz ud])/det([uy uz ux]);
bx=det([uy uz w])/det([uy uz ux]);

my=det([ux uz ud])/det([ux uz uy]);
by=det([ux uz w])/det([ux uz uy]);

mz=det([ux uy ud])/det([ux uy uz]);
bz=det([ux uy w])/det([ux uy uz]);

I=mx^2+my^2+mz^2-c^2;
J=2*mx*bx + 2*mx*A1 + 2*my*by + 2*my*B1 + 2*mz*bz + 2*mz*C1 + 2*t1*c^2;
K=bx^2 +2*bx*A1 +A1^2 +by^2 +2*by*B1 +B1^2 +bz^2 +2*bz*C1 +C1^2 -c^2*t1^2;

D(1)=(-J + sqrt(J^2-4*I*K))/(2*I);
D(2)=(-J - sqrt(J^2-4*I*K))/(2*I);

%other solution
x=-D(2)*mx -bx
y=-D(2)*my -by
z=-D(2)*mz -bz


xx=-D(1)*mx -bx
yy=-D(1)*my -by
zz=-D(1)*mz -bz

out=[ xx, yy, zz, D(1)]





    
    
